package com.sgb.kjwl.view.ui.adapter.self.goods;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemVipPriceMangeBinding;
import com.sgb.kjwl.model.entity.self.VipPriceMangeListEntity;
import com.sgb.kjwl.utils.AbScreenUtils;
import com.sgb.kjwl.utils.PointUtils;
import com.sgb.kjwl.view.ui.adapter.map.BaseRecycleAdapter;
import com.sgb.kjwl.view.ui.adapter.map.ItemViewHolder;
import com.swgk.core.util.TimeUtil;

import java.util.ArrayList;
import java.util.List;

public class VipPriceManageListAdpater extends BaseRecycleAdapter<VipPriceMangeListEntity> {

    /**结束会员价**/
    public static final int COLOSVIPPRICE = 0x11;
    /**再次设置会员价**/
    public static final int SETORICEAGIN = 0x12;
    public VipPriceManageListAdpater(Context context) {
        super(context, R.layout.item_vip_price_mange, new ArrayList<>());
    }

    @Override
    public void convert(ItemViewHolder holder, VipPriceMangeListEntity vipPriceMangeListEntity) {

        holder.getmBinding().setVariable(BR.model,vipPriceMangeListEntity);
        if(holder.getmBinding() instanceof ItemVipPriceMangeBinding){

            String pinpai = "/";
            if(!TextUtils.isEmpty(vipPriceMangeListEntity.getBrandName())){
                pinpai = vipPriceMangeListEntity.getBrandName();
                if(!TextUtils.isEmpty(vipPriceMangeListEntity.getStorageName())){
                    pinpai = pinpai+" | "+vipPriceMangeListEntity.getStorageName();
                }
            }else if(!TextUtils.isEmpty(vipPriceMangeListEntity.getStorageName())){
                pinpai = vipPriceMangeListEntity.getStorageName();
            }

            if(!TextUtils.isEmpty(pinpai)){
                ((ItemVipPriceMangeBinding) holder.getmBinding()).tvPinpai.setText(pinpai);
            }


            if(vipPriceMangeListEntity.getPriceMax()==0&&vipPriceMangeListEntity.getPriceMin()==0){
                ((ItemVipPriceMangeBinding) holder.getmBinding()).tvPrice.setText(PointUtils.price(vipPriceMangeListEntity.getPrice())+"/"+vipPriceMangeListEntity.getUnit());
            }else{
                ((ItemVipPriceMangeBinding) holder.getmBinding()).tvPrice.setText(PointUtils.price(vipPriceMangeListEntity.getPriceMin())+"-"+PointUtils.price(vipPriceMangeListEntity.getPriceMax())+"/"+vipPriceMangeListEntity.getUnit());
            }

            if(vipPriceMangeListEntity.getImageList()!=null&&vipPriceMangeListEntity.getImageList().length>0){
                RequestOptions options = new RequestOptions().transform(new CenterCrop(),new RoundedCorners(AbScreenUtils.dp2px(context,4)))
                        .placeholder(R.mipmap.image_order_list_defuntimage)
                        .error(R.mipmap.image_order_list_defuntimage);
                Glide.with(context).load(vipPriceMangeListEntity.getImageList()[0]).apply(options).into(((ItemVipPriceMangeBinding) holder.getmBinding()).image);
            }

            ((ItemVipPriceMangeBinding) holder.getmBinding()).imageType.setImageResource(vipPriceMangeListEntity.getStatus()==1?R.mipmap.image_vipprie_shenxiao:R.mipmap.image_vipprie_shixiao);
            ((ItemVipPriceMangeBinding) holder.getmBinding()).tvUpdatetime.setText(TimeUtil.getDateStringYMD(vipPriceMangeListEntity.getUpdateTime())+" 更新");
            ((ItemVipPriceMangeBinding) holder.getmBinding()).tvBtn.setBackgroundResource(vipPriceMangeListEntity.getStatus()==1?R.drawable.shape_vip_price_btn1:R.drawable.shape_vip_price_btn2);
            ((ItemVipPriceMangeBinding) holder.getmBinding()).tvBtn.setText(vipPriceMangeListEntity.getStatus()==1?"结束会员价":"再次设置");
            ((ItemVipPriceMangeBinding) holder.getmBinding()).tvBtn.setOnClickListener(v->{
                onItemClick.onItemClick(vipPriceMangeListEntity,vipPriceMangeListEntity.getStatus()==1?COLOSVIPPRICE:SETORICEAGIN);
            });
        }

    }
}
